<template>
  <div>
    <crumbs :BreadCrumb="BreadCrumb"></crumbs>
    <div>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="姓名/手机号">
          <el-input v-model="formInline.user" clearable></el-input>
        </el-form-item>
        <el-form-item label="身份证号">
          <el-input v-model="formInline.user" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            icon="el-icon-search"
            type="primary"
            @click="queryPbPersonsList()"
          ></el-button>
        </el-form-item>
        <el-form-item class="staff_form_btn">
          <el-button>重置</el-button>
        </el-form-item>
        <!-- <el-form-item class="staff_form_btn">
                    <el-button @click="dialogFormVisible = true"
                      >刷身份证弹出</el-button
                    >
                  </el-form-item> -->
        <el-form-item class="staff_form_btn">
          <el-button @click="dialogFormVisibles = true">模拟来电</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="options">
      <div class="options_div">
        <h3 style="text-align: right">预约人数：429人，已签到：109人</h3>
        <br />
      </div>
      <el-tabs type="border-card">
        <el-tab-pane label="今日登记名单">
          <div>
            <el-form
              :inline="true"
              :model="formInline"
              class="demo-form-inline"
            >
              <div class="disflex">
                <div>
                  <el-form-item label="">
                    <el-radio-group v-model="formInline.resource">
                      <el-radio label="全部"></el-radio>
                      <el-radio label="未交表"></el-radio>
                      <el-radio label="已交表"></el-radio>
                    </el-radio-group>
                  </el-form-item>
                </div>
                <div>
                  <el-form-item label="">
                    <el-checkbox-group v-model="form.type">
                      <el-checkbox label="未打打印" name="type"></el-checkbox>
                      <el-checkbox label="待缴费" name="type"></el-checkbox>
                    </el-checkbox-group>
                  </el-form-item>
                </div>
                <div>
                  <el-form-item class="staff_form_btn">
                    <el-button type="primary">打印指引单</el-button>
                  </el-form-item>
                  <el-form-item class="staff_form_btn">
                    <el-button type="primary">打印条码</el-button>
                  </el-form-item>
                </div>
              </div>
            </el-form>
          </div>
          <div>
            <el-table
              ref="multipleTable"
              :data="tableData"
              tooltip-effect="dark"
              style="width: 100%"
              @selection-change="handleSelectionChange"
            >
              <el-table-column type="selection" width="55"> </el-table-column>
              <el-table-column label="姓名" width="120">
                <template slot-scope="scope">{{ scope.row.date }}</template>
              </el-table-column>
              <el-table-column prop="name" label="性别" width="120">
              </el-table-column>
              <el-table-column
                prop="address"
                label="年龄"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="address"
                label="联系方式"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="address"
                label="单位名称"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="address"
                label="体检类型"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="address"
                label="体检套餐"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="address"
                label="体检类型"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="address"
                label="体检进度"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="address"
                label="登记时间"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="address"
                label="体检状态"
                show-overflow-tooltip
              >
              </el-table-column>
            </el-table>
          </div>
          <div class="pagination">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="pageNo"
              :page-sizes="[100, 200, 300, 400]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="400"
            >
            </el-pagination>
          </div>
        </el-tab-pane>
        <el-tab-pane label="近期待检名单">
          <div>
            <el-form
              :inline="true"
              :model="formInline"
              class="demo-form-inline"
            >
              <div class="disflex">
                <div>
                  <el-form-item label="">
                    <el-radio-group v-model="formInline.resource">
                      <el-radio label="全部"></el-radio>
                      <el-radio label="今日"></el-radio>
                      <el-radio label="明日"></el-radio>
                    </el-radio-group>
                  </el-form-item>
                </div>
                <div>
                  <el-form-item label="">
                    <el-radio-group v-model="formInline.resource">
                      <el-radio label="未预约"></el-radio>
                      <el-radio label="已预约"></el-radio>
                    </el-radio-group>
                  </el-form-item>
                </div>
                <div></div>
              </div>
            </el-form>
          </div>
          <div>
            <el-table
              ref="multipleTable"
              :data="tableData"
              tooltip-effect="dark"
              style="width: 100%"
              @selection-change="handleSelectionChange"
            >
              <el-table-column type="selection" width="55"> </el-table-column>
              <el-table-column label="体检单号" width="120">
                <template slot-scope="scope">{{ scope.row.date }}</template>
              </el-table-column>
              <el-table-column prop="name" label="姓名" width="120">
              </el-table-column>
              <el-table-column prop="name" label="性别" width="120">
              </el-table-column>
              <el-table-column
                prop="address"
                label="年龄"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="address"
                label="联系方式"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="address"
                label="单位名称"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="address"
                label="体检类型"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="address"
                label="体检套餐"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="address"
                label="体检类型"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="address"
                label="体检进度"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="address"
                label="登记时间"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="address"
                label="体检状态"
                show-overflow-tooltip
              >
              </el-table-column>
            </el-table>
          </div>
          <div class="pagination">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage4"
              :page-sizes="[100, 200, 300, 400]"
              :page-size="100"
              layout="total, sizes, prev, pager, next, jumper"
              :total="400"
            >
            </el-pagination>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
    <!-- 刷身份弹出 -->
    <el-dialog
      title="体检登记"
      :visible.sync="dialogFormVisible"
      width="1500px"
      class="top_dialog"
    >
      <el-form :model="form" label-position="left">
        <div class="add_info">
          <userinfos></userinfos>
          <div class="info_r">
            <div class="info_l_head">
              <h3>体检项目->精英组合套餐（男组）</h3>
              <el-divider></el-divider>
            </div>
            <div>
              <div class="">
                <div class="">
                  <!-- <el-upload
                    class="avatar-uploader"
                    action="https://jsonplaceholder.typicode.com/posts/"
                    :show-file-list="false"
                    :on-success="handleAvatarSuccess"
                    :before-upload="beforeAvatarUpload"
                  > -->
                  <el-button class="ldog_butn" @click="getCompetence()"
                    >打开摄像头</el-button
                  >
                  <el-button class="ldog_butn" @click="stopNavigator()"
                    >关闭摄像头</el-button
                  >
                  <el-button
                    v-if="camerais"
                    class="ldog_butn"
                    @click="setImage()"
                    >拍照</el-button
                  >
                  <!-- </el-upload> -->

                  <div class="photog">
                    <video
                      v-show="!imgSrc"
                      id="videoCamera"
                      :width="videoWidth"
                      :height="videoHeight"
                      autoplay
                    ></video>
                    <canvas
                      style="display: none"
                      id="canvasCamera"
                      :width="videoWidth"
                      :height="videoHeight"
                    ></canvas>
                    <div v-if="imgSrc" class="photog">
                      <img :src="imgSrc" alt="" class="tx_img" />
                    </div>
                  </div>
                  <div class="form_div">
                    <div class="form_div_l">
                      <el-form-item label="" prop="type">
                        <el-checkbox-group v-model="form.type">
                          <el-checkbox
                            label="使用电子导引单"
                            name="type"
                          ></el-checkbox>
                        </el-checkbox-group>
                      </el-form-item>
                    </div>
                    <div>
                      <el-form-item>
                        <el-button @click="resetForm('ruleForm')"
                          >打印体检导引单</el-button
                        >
                      </el-form-item>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogFormVisible = false"
          >保 存</el-button
        >
        <el-button @click="dialogFormVisible = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 模拟来电弹出 -->
    <el-dialog
      title="来电弹出"
      :visible.sync="dialogFormVisibles"
      width="90%"
      class="top_dialog"
    >
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <div>
          <el-form-item label="来电电话">
            <el-input v-model="formInline.user" clearable></el-input>
          </el-form-item>
          <el-form-item label="姓名">
            <el-input v-model="formInline.user" clearable></el-input>
          </el-form-item>
          <el-form-item label="性别">
            <el-input v-model="formInline.user" clearable></el-input>
          </el-form-item>
          <el-form-item label="单位">
            <el-input v-model="formInline.user" clearable></el-input>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="来电时间">
            <el-input v-model="formInline.user" clearable></el-input>
          </el-form-item>
        </div>
      </el-form>
      <div>
        <h3>体检史</h3>
        <br />
        <el-table height="250" :data="tableDatas" border style="width: 100%">
          <el-table-column prop="date" label="体检单号" width="100">
          </el-table-column>
          <el-table-column prop="name" label="姓名" width="120">
          </el-table-column>
          <el-table-column prop="name" label="性别" width="80">
          </el-table-column>
          <el-table-column prop="name" label="年龄" width="80">
          </el-table-column>
          <el-table-column prop="name" label="单位" width="180">
          </el-table-column>
          <el-table-column prop="name" label="体检套餐" width="140">
          </el-table-column>
          <el-table-column prop="name" label="体检状态" width="140">
          </el-table-column>
          <el-table-column prop="name" label="下单时间" width="140">
          </el-table-column>
          <el-table-column prop="name" label="预约/时间" width="140">
          </el-table-column>
          <el-table-column prop="name" label="体检时间" width="180">
          </el-table-column>
          <el-table-column prop="name" label="操作" width="220" fixed="right">
            <template slot-scope="scope">
              <el-button
                @click="handleClick(scope.row)"
                type="success"
                size="small"
                >预约</el-button
              >
              <el-button
                type="primary"
                @click="handleClick(scope.row)"
                size="small"
                >改约</el-button
              >
              <el-button @click="handleClick(scope.row)" size="small"
                >加项</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <div class="block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage4"
            :page-sizes="[100, 200, 300, 400]"
            :page-size="100"
            layout="total, sizes, prev, pager, next, jumper"
            :total="400"
          >
          </el-pagination>
        </div>
      </div>
      <div class="lai_div">
        <div class="lai_div_l">
          <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="活动形式">
              <el-input
                type="textarea"
                :autosize="{ minRows: 4, maxRows: 4 }"
                v-model="form.desc"
              ></el-input>
            </el-form-item>
            <el-form-item label="活动名称">
              <el-select v-model="form.region" placeholder="请选择活动区域">
                <el-option label="区域一" value="shanghai"></el-option>
                <el-option label="区域二" value="beijing"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </div>
        <div class="lai_div_r">
          <el-button type="primary">快捷</el-button>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogFormVisibles = false"
          >保 存</el-button
        >
        <el-button @click="dialogFormVisibles = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 体检预约新增、编辑 -->
    <el-dialog
      title="体检预约新增、编辑"
      :visible.sync="handleClickis"
      width="70%"
      class="top_dialog"
    >
      <el-form :model="form" label-width="80px" label-position="left">
        <div class="add_info">
          <div class="info_l">
            <div class="info_l_head">
              <h3>基本信息</h3>
              <el-divider></el-divider>
            </div>
            <div>
              <el-form-item label="姓名">
                <el-input v-model="form.user" clearable></el-input>
              </el-form-item>
              <el-form-item label="性别">
                <el-input v-model="form.user" clearable></el-input>
              </el-form-item>
              <el-form-item label="年龄">
                <el-input v-model="form.user" clearable></el-input>
              </el-form-item>
              <el-form-item label="电话">
                <el-input v-model="form.user" clearable></el-input>
              </el-form-item>
              <el-form-item label="单位">
                <el-input v-model="form.user" clearable></el-input>
              </el-form-item>
            </div>
            <div class="info_l_head">
              <h3>体检信息</h3>
              <el-divider></el-divider>
            </div>
            <div>
              <el-form-item label="体检编号">
                <el-input v-model="form.user" clearable></el-input>
              </el-form-item>
              <el-form-item label="体检套餐">
                <el-input v-model="form.user" clearable></el-input>
              </el-form-item>
              <el-form-item label="预约时间">
                <el-date-picker
                  v-model="form.value1"
                  type="date"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </el-form-item>
            </div>
          </div>
          <div class="info_r">
            <div class="info_l_head">
              <h3>预约编辑</h3>
              <el-divider></el-divider>
            </div>
            <div>
              <div style="display: flex">
                <div>
                  <el-form-item label="预约日期">
                    <el-date-picker
                      v-model="form.value1"
                      type="date"
                      placeholder="选择日期"
                    >
                    </el-date-picker>
                  </el-form-item>
                </div>
                <div style="margin-left: 20px">
                  <el-form-item label="预约时间">
                    <el-time-picker
                      v-model="form.value1"
                      :picker-options="{
                        selectableRange: '08:00:00 - 20:30:00',
                      }"
                      placeholder="任意时间点"
                    ></el-time-picker>
                  </el-form-item>
                </div>
              </div>
              <el-form-item label="体检编号">
                <el-input
                  type="textarea"
                  :autosize="{ minRows: 7, maxRows: 7 }"
                  v-model="form.user"
                  clearable
                ></el-input>
              </el-form-item>
              <el-form-item label="">
                <div class="yvyue_div">
                  <el-button>选择叮嘱内容</el-button>
                  <el-button>立即推送消息</el-button>
                  <el-button>查看消息</el-button>
                </div>
              </el-form-item>
            </div>
          </div>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleClickis = false"
          >保 存</el-button
        >
        <el-button @click="handleClickis = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script >
import Vue from "vue";

import userinfos from "../common/userinfos.vue";
import crumbs from "../../views/Crumbs.vue";
export default {
  components: {
    crumbs,
    userinfos,
  },
  data() {
    return {
      camerais: false,
      videoWidth: 600,
      videoHeight: 400,
      imgSrc: "",
      thisCancas: null,
      thisContext: null,
      thisVideo: null,
      tableDatas: [
        {
          name: "234",
        },
      ],
      handleClickis: false,
      dialogFormVisible: false,
      dialogFormVisibles: false,
      form: {
        type: "213",
      },
      formLabelWidth: "80px",
      formInline: {},
      pageNo:1,
      pageSize:10,
      BreadCrumb: [
        { path: "", name: "检前管理" },
        { path: "/basic/staff", name: "参检人员登记" },
      ],
    };
  },
  methods: {
    // 预约弹框
    handleClick() {
      this.handleClickis = true;
    },
    // 打开照相机
    getCompetence() {
      var _this = this;
      _this.imgSrc = "";
      _this.camerais = true;
      this.thisCancas = document.getElementById("canvasCamera");
      this.thisContext = this.thisCancas.getContext("2d");
      this.thisVideo = document.getElementById("videoCamera");
      // 旧版本浏览器可能根本不支持mediaDevices，我们首先设置一个空对象
      if (navigator.mediaDevices === undefined) {
        navigator.mediaDevices = {};
      }
      // 一些浏览器实现了部分mediaDevices，我们不能只分配一个对象
      // 使用getUserMedia，因为它会覆盖现有的属性。
      // 这里，如果缺少getUserMedia属性，就添加它。
      if (navigator.mediaDevices.getUserMedia === undefined) {
        navigator.mediaDevices.getUserMedia = function (constraints) {
          // 首先获取现存的getUserMedia(如果存在)
          var getUserMedia =
            navigator.webkitGetUserMedia ||
            navigator.mozGetUserMedia ||
            navigator.getUserMedia;
          // 有些浏览器不支持，会返回错误信息
          // 保持接口一致
          if (!getUserMedia) {
            return Promise.reject(
              new Error("getUserMedia is not implemented in this browser")
            );
          }
          // 否则，使用Promise将调用包装到旧的navigator.getUserMedia
          return new Promise(function (resolve, reject) {
            getUserMedia.call(navigator, constraints, resolve, reject);
          });
        };
      }
      var constraints = {
        audio: false,
        video: {
          width: this.videoWidth,
          height: this.videoHeight,
          transform: "scaleX(-1)",
        },
      };
      navigator.mediaDevices
        .getUserMedia(constraints)
        .then(function (stream) {
          // 旧的浏览器可能没有srcObject
          if ("srcObject" in _this.thisVideo) {
            _this.thisVideo.srcObject = stream;
          } else {
            // 避免在新的浏览器中使用它，因为它正在被弃用。
            _this.thisVideo.src = window.URL.createObjectURL(stream);
          }
          _this.thisVideo.onloadedmetadata = function (e) {
            _this.thisVideo.play();
          };
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 绘制图片（拍照功能）

    setImage() {
      var _this = this;
      // 点击，canvas画图
      _this.thisContext.drawImage(
        _this.thisVideo,
        0,
        0,
        _this.videoWidth,
        _this.videoHeight
      );
      // 获取图片base64链接
      var image = this.thisCancas.toDataURL("image/jpg");
      _this.imgSrc = image;
      this.$emit("refreshDataList", this.imgSrc);
    },
    // base64转文件

    dataURLtoFile(dataurl, filename) {
      var arr = dataurl.split(",");
      var mime = arr[0].match(/:(.*?);/)[1];
      var bstr = atob(arr[1]);
      var n = bstr.length;
      var u8arr = new Uint8Array(n);
      while (n--) {
        u8arr[n] = bstr.charCodeAt(n);
      }
      return new File([u8arr], filename, { type: mime });
    },
    // 关闭摄像头

    stopNavigator() {
      this.camerais = false;
      this.thisVideo.srcObject.getTracks()[0].stop();
    },
  },
};
</script>

<style scoped>
.pagination {
  text-align: center;
}
.disflex {
  display: flex;
  justify-content: space-between;
}

.main_box_title {
  background: #fff;
  padding: 10px;
}
.aside_box_title {
  margin: 0px 8px 10px;
  /* text-align: center; */
}
.header_top .el-divider--horizontal {
  margin-top: 0px;
}
.add_info .el-divider--horizontal {
  margin-top: 10px;
}
.add_info {
  display: flex;
  padding: 0px 20px;
}
.el-main {
  padding: 0px;
  padding-left: 20px;
}
.staff_form_btn {
}
.info_l {
  text-align: left;
  flex: 1;
}
.info_r {
  text-align: left;
  flex: 1;
  margin-left: 30px;
}
.info_l_input {
  width: 82%;
}
.info_l_button {
  margin-left: 10px;
}
.info_sel_r_groupn {
  margin-left: 40px;
}
.info_sel_r_group {
  margin-left: 10px;
}
.info_sel {
  display: flex;
}
.info_sel_l {
  width: 50%;
}
.info_sel_r {
  width: 50%;
  margin-left: 50px;
}
.info_sel_r_img {
  width: 180px;
  height: 220px;
  margin: 0px auto;
}
.avatar-uploader {
  margin: 0px auto;
  text-align: center;
}
.info_l /deep/ .el-select {
  width: 100%;
}
.info_l_head {
}
.pagination {
  text-align: center;
}
.top_dialog /deep/ .el-dialog {
  margin-top: 3vh !important;
}
.photog {
  width: 600px;
  height: 400px;
  margin: 10px auto;
}
.photog video {
  width: 600px;
  height: 400px;
}
.photog canvas {
  width: 600px;
  height: 400px;
}
.info_sel_s_butn {
  margin: 0px auto;
}
.info_sel_butn {
  margin-left: 20px;
}
.info_sel_s {
  margin-left: 20px;
}
.ldog_butn {
  width: 120px;
  height: 50px;
  margin: 0px auto;
}
.form_div {
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  padding: 0px 30px;
}
.block {
  text-align: center;
}
.lai_div {
  margin-top: 20px;
  display: flex;
}
.lai_div_l {
  width: 480px;
}
.lai_div_l /deep/ .el-input--suffix {
  width: 400px;
}
.lai_div_r {
  margin-left: 20px;
}
.yvyue_div {
  display: flex;
  justify-content: space-between;
}
.yvyue_div button {
  width: 150px;
}
.options {
  position: relative;
}
.options_div {
  position: absolute;
  top: 5px;
  right: 10px;
  z-index: 99 !important;
}
</style>
